import greenfoot.*;  // (World, Actor, GreenfootImage, Greenfoot and MouseInfo)

/**
 * Write a description of class AND here.
 * 
 * @author Christian Pérez Zavalija
 * @version 25-Jun-2013
 */
public class AND extends Circuit
{
    private GreenfootImage imgAnd;
    
    /**
     * Load image and displays.
     */
    public AND()
    {
        imgAnd=new GreenfootImage("AND.png");
        setImage(imgAnd);
    }
    
    
    /**
     * The image is scale in 50%
     */
    public void scale()
    {
        imgAnd.scale(imgAnd.getWidth()-50,imgAnd.getHeight()-40);
    }
    
    /**
     * It drives the circuit logic AND(7408) in the input pins for establish a charge on the respective output pin.
     * 
     * @param into number pinA and number pin B.
     */
    public void logicAND(int A, int B)
    {
        if(pins[A].charge==1&&pins[B].charge==1)
            pins[B+1].charge=1;
        else
            pins[B+1].charge=0;
    }
    
    /**
     * Method calls the act () of its superclass. Check if the circuit is energized and if the
     * values ​​of the input pins are different garbage charge.
     */
    public void act() 
    {
        super.act();
        if(pins[6].charge==0&&pins[7].charge==1){
            if(pins[0].charge<2&&pins[1].charge<2)
                this.logicAND(0,1);
            if(pins[3].charge<2&&pins[4].charge<2)
                this.logicAND(3,4);
            if(pins[11].charge<2&&pins[12].charge<2)
                this.logicAND(11,12);
            if(pins[8].charge<2&&pins[9].charge<2)
                this.logicAND(8,9);
        }
    }    
}
